package com.ycj.entropy;

import android.content.Context;
import android.util.JsonReader;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.alibaba.fastjson.JSON;
import com.ycj.entropy.data.DaoFactory;
import com.ycj.entropy.data.Study;
import com.ycj.entropy.data.StudyDao;

import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.*;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
        assertEquals("com.ycj.entropy", appContext.getPackageName());
    }

    @Test
    public void testDb() {
        Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
        DaoFactory.init(context);
        StudyDao dao = DaoFactory.studyDao();

        Study study = new Study();
        study.setImageList(Arrays.asList("1.jpg", "2.jpg"));
        study.setContent("hello");

        dao.insert(study);
        List<Study> list = dao.list();

        System.out.println();
    }

    @Test
    public void query() {
        Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
        DaoFactory.init(context);
        StudyDao dao = DaoFactory.studyDao();
        List<Study> studies = dao.list();
        System.out.println(JSON.toJSONString(studies));
    }
}